using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace ASP_TF2LogParser.BR
{
    public class User
    {

        #region Private Member Variables

        private string _login = string.Empty;
        private bool _admin = false;
        private string _email = string.Empty;
        private DateTime _lastLogin = new DateTime();
        private bool _isValid = false;

        #endregion

        #region Public Properties

        public string Login
        {
            get { return _login; }
            set { _login = value; }
        }

        public bool Admin
        {
            get { return _admin; }
            set { _admin = value; }
        }

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }

        public DateTime LastLogin
        {
            get { return _lastLogin; }
            set { _lastLogin = value; }
        }

        public bool IsValid
        {
            get { return _isValid; }
            set { _isValid = value; }
        }

        #endregion

        public User()
        {

        }

        public User( string login, string password )
        {
            LogParser.DA.DataObjects.UsersDS.UsersSelectRow dr = LogParser.DA.UserModel.UsersSelectDataTableAuthenticate( login, password );

            if ( dr != null )
            {
                DateTime lastLogin = DateTime.Now;

                LogParser.DA.UserModel.UsersLastLoginUpdate( login, lastLogin );

                _isValid = true;
                _login = login;
                _lastLogin = lastLogin;
                _email = dr.Email;
                _admin = dr.Admin;
            }
            else
            {
                _isValid = false;
            }


        }

    }
}
